/*******************************************************************************
 * Copyright (c) 2010, 2030 www.itlaobing.cn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package cn.itlaobing.web.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.itlaobing.exception.MyBusinessException;
import cn.itlaobing.model.OrderModel;
import cn.itlaobing.model.UserModel;
import cn.itlaobing.service.OrderService;
import cn.itlaobing.service.UserService;
import cn.itlaobing.util.DateUtil;
import cn.itlaobing.web.annotation.RequestMapping;

/** 
 * ClassName: Servlet <br/> 
 * Function: TODO 功能描述 <br/> 
 * date: 2017年10月31日 下午9:17:01 <br/> 
 * 
 * @author lhb 
 * @version  
 * @since JDK 1.8 
 */
@WebServlet(value="/user/*",loadOnStartup=1)
public class Servlet extends BaseServlet{

	
	@RequestMapping("/login")
	public void login(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
		String username=request.getParameter("username");
		String userpwd=request.getParameter("userpwd");
		UserService us=new UserService();
		OrderService os=new OrderService();
		UserModel userModel=null;
            try {
                userModel=us.login(username, userpwd);
                //得到上次登录时间
                if (userModel!=null) {
                    String date = DateUtil.getDate(userModel.getLastlogintime());
                    request.getSession().setAttribute("DATE", date);
                    request.getSession().setAttribute("USER", userModel);
                    response.sendRedirect("/order/show");
                    return;
                }
            } catch (MyBusinessException e) {
                e.printStackTrace();
            }
        if(userModel==null) {
            request.setAttribute("msg","用户名或密码错误！");
            request.getRequestDispatcher("/login.jsp").forward(request,response);
            return;
        }



	}
}
